package org.mogu.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import org.mogu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

/*
 * 最近联系的数据适配器
 * @author androidSource@139.com
 * */
public class SetStatusListAdapter extends BaseAdapter {
	//所属activity
	private Context mContext = null;
	//设置状态的数据
	public ArrayList SetStautsArrayList = null;
	
	public void setSetStautsArrayList(ArrayList setStautsArrayList) {
		SetStautsArrayList = setStautsArrayList;
	}

	//加载布局文件的对象
	private LayoutInflater mLayoutInflater = null;	

	//构造函数
	public SetStatusListAdapter(Context paramContext,ArrayList SetStautsArrayList){
		 mContext = paramContext;
		 mLayoutInflater = LayoutInflater.from(mContext);
		 
		 this.SetStautsArrayList = SetStautsArrayList;
	}
	
	/*
	 * 获得list的列表项总数
	 * */
	public int getCount(){
	    return (SetStautsArrayList != null)?SetStautsArrayList.size():0;
	}

	/*
	 * 获得list的列表项
	 * */
	public Object getItem(int paramInt){
		 return (SetStautsArrayList != null)?SetStautsArrayList.get(paramInt):null;
	}

	/*
	 * 获得list的列表项下标
	 * */
	public long getItemId(int paramInt){
	    return paramInt;
	}

	/*
	 * 列表项的视图函数
	 * */
	public View getView(int paramInt, View paramView, ViewGroup paramViewGroup){
		View localView = paramView;
		
		HashMap statusHashMap = (HashMap)SetStautsArrayList.get(paramInt);
		
		//判断当前view视图参数是否为null
		if (localView == null){
			//加载一级视图的布局文件
			localView = mLayoutInflater.inflate(R.layout.qq_dialog_set_status_row, null);
		}
		
		/*
		 * 相关控件设置
		 * */
		//在线状态标识
		ImageView status = (ImageView)localView.findViewById(R.id.status);
		//在线状态字符串
		TextView statusString = (TextView)localView.findViewById(R.id.statusString);
		//在线标识选择
		RadioButton statusRadio = (RadioButton)localView.findViewById(R.id.statusRadio);
		
		Integer statusResId = (Integer)statusHashMap.get("img");
		status.setImageResource(statusResId);
		statusString.setText(statusHashMap.get("name").toString());
		
		Boolean statusRadioState = (Boolean)statusHashMap.get("isChecked");
		statusRadio.setChecked(statusRadioState);
		
	    return localView;
	}
  
}